package com.aaa.service.impl;


import com.aaa.entity.DO.RentOverdue;
import com.aaa.entity.query.PageQuery;
import com.aaa.entity.query.RentOverdueQuery;
import com.aaa.entity.result.Result;
import com.aaa.mapper.RentOverdueMapper;
import com.aaa.mapper.RentOverdueOperationMapper;
import com.aaa.service.RentOverdueService;
import com.aaa.util.NotNullUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：陈凯歌
 * @date ：Created in 2021/2/2 17:34
 * @description：租金逾期服务接口实现类
 * @modified By：
 * @version: 1.0
 */
@Service
public class RentOverdueServiceImpl implements RentOverdueService {

    @Autowired
    private RentOverdueMapper mapper;

    @Autowired
    RentOverdueOperationMapper rentOverdueOperationMapper;

    /**
     * create by: 陈凯歌
     * description: 租金逾期业务分页+模糊查询
     * create time: 2021/2/2 17:38
     *
      * @Param: query
     * @return Result
     */

    @Override
    public Result getPage(RentOverdueQuery query) {

        //创建wraper对象
        QueryWrapper<RentOverdue> wrapper = new QueryWrapper<>();
        //判断数据库与传入对象中的变量字段是否相同，如果相同判断是否存在此数据
        wrapper.like(NotNullUtils.StringUtils(query.getLeaser()),"leaser" ,query.getLeaser());
        //基础分页,参数传入起始页与每页数量
        Page<RentOverdue> page = new Page<>(query.getPage(),query.getCount());
        //调用分页方法
        Page<RentOverdue> rentOverduePage = mapper.selectPage(page, wrapper);


        return Result.succeed(rentOverduePage);
    }

    /**
     * create by: 陈凯歌
     * description: 根据租金逾期id查询细粒度操作
     * create time: 2021/2/3 14:53
     * 
      * @Param: null
     * @return 
     */
    
    @Override
    public Result listAll(Integer id) {

        List<RentOverdue> list = mapper.listAll(id);
        //判断集合是否为空
        if (list!=null && list.size()>0){
            //返回成功数据
            return Result.succeed(list);
        }
        return Result.error("查询失败");
    }

    /**
     * create by: 陈凯歌
     * description: 根据id删除某条详细信息
     * create time: 2021/2/3 15:02
     * 
      * @Param: null
     * @return 
     */
    
    @Override
    public Result delOverdue(Integer id) {

        int i = rentOverdueOperationMapper.deleteById(id);
        //判断受影响条数是否大于0
        if (i>0){
            //大于则返回结果
            return Result.succeed("删除成功");
        }
        return Result.succeed("删除失败");
    }
}
